import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router"
const routes: RouteRecordRaw[] = [
	{
		path: "/",
		name: "Login",
		component: () => import("@/views/sysLogin/index.vue") // 注意这里要带上 文件后缀.vue
	},
	{
		path: "/home",
		name: "Home",
		component: () => import("@/views/home/index.vue")
	}
]

const router = createRouter({
	history: createWebHistory(),
	routes
})

// 路由前置守卫
router.beforeEach((to, from, next) => {
	// token失效自动返回登录
	if (!localStorage.getItem("token") && to.path !== "/") {
		next({ path: "/" })
	}
	next()
})

export default router
